/**
 * 
 */
package com.zhaoyan.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.zhaoyan.entity.Order;
import com.zhaoyan.entity.OrderVo;
import com.zhaoyan.service.OrderService;

/**
 * @author zhaoyan
 *
 * 2020年2月10日
 */
@Controller
public class OrderController {
	
	
	@Autowired
	private OrderService orderService;
	
	/**
	 * 
	 * @param pageNum 当前页数
	 * @param order 查询条件
	 * @param m	数据渲染
	 * @return
	 */
	@RequestMapping("/")
	public String orderList(@RequestParam(defaultValue = "1")Integer pageNum , OrderVo ordervo ,Model m) {
		
		PageInfo<Order> orderPage = orderService.orderList(pageNum,ordervo);
		
		m.addAttribute("orderPage",orderPage );
		m.addAttribute("ordervo",ordervo);
		
		return "list";
	}
	
	
	@RequestMapping("delList")
	@ResponseBody
	public Integer delList(@RequestParam(required = false,value = "ids")List<Integer> ids) {
		
		if(ids == null) {
			return 5;
		}
		
		
		return orderService.delList(ids);
	}
	
	
	@RequestMapping("showDetail")
	public String detailOrder(Integer id,Model m) {
		System.out.println(id);
		Order order = orderService.showDetail(id);
		System.out.println(order);
		m.addAttribute("order",order);
		return "detail";
	}

}
